@echo off & setlocal EnableDelayedExpansion %确保参数能准确的赋值%
chcp 65001 %设置UTF8编码%
set obj[0]=6605

set port=0
set pid=0

for /f "usebackq delims== tokens=1-2" %%a in (`set obj`) do (
    set port=%%b
	echo 开始查找端口号【!port!】被占用的进程
    for /f "tokens=5" %%m in ('netstat -aon ^| findstr ":%%b"') do (
        set pid=%%m
    )
    if "!pid!"=="0" (
        echo 端口号【!port!】没有被占用
    ) else (
        echo 端口号【!port!】相关进程【!pid!】已关闭
        taskkill /f /pid !pid!
    )
    set pid=0
)